const {createReply, updateReply, delReply} = require('../service/reply')
const {SuccessModel, ErrorModel} = require('../model/ResModel')
const {addRoleFailInfo} = require('../model/ErrorInfo')

const postReply = async (ctx, {content, contentId}) => {
  const result = await createReply({content, uid: ctx.session.user.user.id, contentId})
  return result ? new SuccessModel(result) : new ErrorModel(addRoleFailInfo)
}

const patchReply = async ({content, id}) => {
  const result = await updateReply({content, id})
  return result ? new SuccessModel(result) : new ErrorModel(addRoleFailInfo)
}

const deleteReply = async (id) => {
  const result = await delReply(id)
  return result ? new SuccessModel(result) : new ErrorModel(addRoleFailInfo)
}

module.exports = {
  postReply,
  patchReply,
  deleteReply
}
